/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jm.web;

import java.util.Random;

/**
 *
 * @author Jorge
 */
public class Cadena {
    public static String html_decode(String html)
    {
        html = html.replace("&lt;", "<");
        html = html.replace("&gt;", ">");
        html = html.replace("&amp;", "&");
        return html;
    }
    
    public static String setSecuencial(String numero)
    {
        String relleno = "";
        for(int i=0; i<(9-numero.length()); i++){
            relleno += "0";
        }
        return relleno+numero;
    }
    public static String setFecha(String fecha)
    {
        String vecFecha[] = fecha.split("/");
        return (vecFecha[0].length()==1?"0"+vecFecha[0]:vecFecha[0]) + "/" + (vecFecha[1].length()==1?"0"+vecFecha[1]:vecFecha[1]) + "/" +vecFecha[2];
    }
    
    public static String capital(String frase)
    {
        String cap = "";
        if(frase.compareTo("")!=0){
            String vec[] = frase.split(" ");
            String aux = "";
            for(int i=0; i<vec.length; i++){
                if(vec[i].compareTo("")!=0){
                    aux = vec[i].trim();
                    cap += aux.substring(0, 1).toUpperCase() + aux.substring(1, aux.length()).toLowerCase() + " ";
                }
            }
        }
        return cap.trim();
    }

    public static String getRandomClave(int limite)
    {
        String clave = "";
        String alfanumero = "0123456789ABCDEF";
        char caracter[] = alfanumero.toCharArray();
        Random rnd = new Random();
        int num_rand = 0;
        for(int i=0; i<limite; i++){
            num_rand = (int)(rnd.nextDouble() * caracter.length);
            clave += caracter[num_rand];
        }
        return clave;
    }
}
